package com.android.djlmapp.activity.my;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.activity.LoginPasswordActivity;
import com.android.djlmapp.activity.home.web.ForgetPwdActivity;
import com.android.djlmapp.activity.my.zhaunchu.ShiMingActivity;
import com.android.djlmapp.activity.my.zhaunchu.ShiMingSucActivity;
import com.android.djlmapp.activity.recharge.AddMoneyActivity;
import com.android.djlmapp.adapter.my.MyBaseRecyclerViewAdapter;
import com.android.djlmapp.adapter.my.MyPwdRecyclerviewAdapter;
import com.android.djlmapp.application.MyApplication;
import com.android.djlmapp.base.BaseActivity;
import com.android.djlmapp.dialog.MyUsualyDialog;
import com.android.djlmapp.tools.global.ConstantsValue;
import com.android.djlmapp.tools.global.PrefUtils;
import com.android.djlmapp.tools.global.ToastUtils;
import com.android.djlmapp.tools.global.UserInfoUtils;
import com.android.readcard.eventbus.Event;
import com.android.readcard.eventbus.EventBusUtil;
import com.android.readcard.eventbus.EventCodes;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.feihong.zhiwenlibrary.dialog.DJLM_PasswordDialog;
import com.feihong.zhiwenlibrary.dialog.PasswordDialogListener;
import com.feihong.zhiwenlibrary.zhiwen.ZhiWenCallBack;
import com.feihong.zhiwenlibrary.zhiwen.ZhiWenDialog;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import me.shaohui.bottomdialog.BaseBottomDialog;
import me.shaohui.bottomdialog.BottomDialog;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.RuntimePermissions;

@RuntimePermissions
public class MyAccountActivity extends BaseActivity implements View.OnClickListener {
    public static final String TAG = "djlm-my: ";
    @BindView(R.id.my_finger_switch)
    Switch myFingerSwitch;
    @BindView(R.id.zhiwen_show)
    LinearLayout zhiwenShow;
    @BindView(R.id.ll_top_back)
    LinearLayout llTopBack;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.home_iv_readpoint)
    ImageView homeIvReadpoint;
    @BindView(R.id.top_notes)
    ImageView topNotes;
    @BindView(R.id.My_rel_photo)
    RelativeLayout MyRelPhoto;
    @BindView(R.id.My_rel_name)
    RelativeLayout MyRelName;
    @BindView(R.id.My_rel_phone)
    RelativeLayout MyRelPhone;
    @BindView(R.id.My_rel_addr)
    RelativeLayout MyRelAddr;
    @BindView(R.id.my_info_w)
    ImageView myInfoPic;
    @BindView(R.id.my_info_phone)
    TextView myInfoPhone;
    @BindView(R.id.my_info_name)
    TextView myInfoName;
    @BindView(R.id.shiming_img)
    ImageView shimingImg;

    private Context mContext;
    private int phoneType = 0;
    List<String> mDataPwd;
    UserInfoUtils utils;
    Unbinder mUnbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_account);
        mUnbinder = ButterKnife.bind(this);
        mContext = getActivity();
        EventBusUtil.register(mContext);
        initData();
        initView();
    }

    @Override
    protected void initData() {
        String[] stringArray = {"登录密码", "支付密码", "支付宝绑定", "银行绑定"};
        mDataPwd = Arrays.asList(stringArray);

        zhiWenDialog = new ZhiWenDialog();
        zhiWenDialog.init(getActivity());

        Log.i(TAG, "zhiWenDialog.isFingerprintEnable(): " + zhiWenDialog.isFingerprintEnable());
        if (zhiWenDialog != null && zhiWenDialog.isFingerprintEnable()) {
            zhiwenShow.setVisibility(View.VISIBLE);

            if (PrefUtils.getBoolean(ConstantsValue.ZHIWEN_STATE, false) && !TextUtils.isEmpty(PrefUtils.getString(ConstantsValue.ZHIWEN_KEY, ""))) {
                myFingerSwitch.setChecked(true);
            } else {
                myFingerSwitch.setChecked(false);
            }
            myFingerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (buttonView.isPressed()) {
                        zhiwen(isChecked);

                    }

                }
            });
        }
    }

    @Override
    protected void initView() {
        homeIvReadpoint.setVisibility(View.GONE);
        topNotes.setVisibility(View.GONE);
        tvName.setText("个人信息");

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_account_pwd);
        MyPwdRecyclerviewAdapter myRecyclerviewAdapter = new MyPwdRecyclerviewAdapter(mDataPwd, getActivity(), R.layout.my_pwd_item);
        recyclerView.setAdapter(myRecyclerviewAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        myRecyclerviewAdapter.setOnItemClickListener(new MyBaseRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                //此处进行监听事件的业务处理
                switch (position) {
                    case 0:
                        Log.i(TAG, "登录密码");
                        Intent intent3 = new Intent(mContext, LoginPasswordActivity.class);
                        intent3.putExtra("type", "1");
                        startActivity(intent3);
                        break;
                    case 1:
                        Log.i(TAG, "支付密码");
                        // 支付密码
                        Intent intent2 = new Intent(mContext, LoginPasswordActivity.class);
                        intent2.putExtra("type", "2");
                        startActivity(intent2);
                        break;
                    case 2:
                        Log.i(TAG, "支付宝绑定");
                        // 绑定支付宝
                        startActivity(new Intent(mContext, BundingZFBActivity.class));
                        break;
                    case 3:
                        Log.i(TAG, "银行绑定");
                        // 绑定银行卡
                        Intent intent5 = new Intent(mContext, BundingActivity.class);
                        intent5.putExtra("bd_type", "1");
                        intent5.putExtra("set_type", "0");
                        startActivity(intent5);
                        break;
                }
            }
        });

        utils = UserInfoUtils.getUserInfoUtilsInstance();
        Log.i(TAG, "utils.getHeadImg(): " + utils.getHeadImg());

        String mobile = utils.getMobile();
        if (!TextUtils.isEmpty(mobile)) {
            mobile = mobile.replace(mobile.substring(3, 7), "****");
        }
        myInfoPhone.setText(mobile);

        String RelName = utils.GetRelName();
        if (!TextUtils.isEmpty(RelName)) {
            RelName = RelName.replace(RelName.substring(0, 1), "*");
        }
        myInfoName.setText(RelName);

        if (utils.GetBDSMRZ().equals("1")) {
            shimingImg.setVisibility(View.VISIBLE);
        }

        // 加载圆形头像
        RequestOptions options = new RequestOptions().bitmapTransform(new CircleCrop())
                .placeholder(R.mipmap.home_nomphoto) //图片加载出来前，显示的图片
                .fallback(R.mipmap.home_nomphoto)  //url为空的时候,显示的图片
                .error(R.mipmap.home_nomphoto); //图片加载失败后，显示的图片

        Glide.with(mContext)
                .load(utils.getHeadImg())
                .apply(options)
                .into(myInfoPic);

    }


    @OnClick({R.id.My_rel_photo, R.id.My_rel_name, R.id.My_rel_phone, R.id.My_rel_addr, R.id.ll_top_back, R.id.zhiwen_show})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_top_back:
                finish();
                break;
            case R.id.My_rel_photo:
                editPhoto();
                break;
            case R.id.My_rel_name:
                if (utils.GetBDSMRZ().equals("1")) {
                    startActivity(new Intent(mContext, ShiMingSucActivity.class));
                }else{
                    startActivity(new Intent(mContext, ShiMingActivity.class));
                }
                break;
            case R.id.My_rel_phone:
                editPhone();
                break;
            case R.id.My_rel_addr:
                // 收货地址（web）
                startActivity(new Intent(mContext, GetAddressActivity.class));
                break;
            case R.id.user_take_photo:
                //拍照
                phoneType = 1;
                MyAccountActivityPermissionsDispatcher.needPermissionWithCheck(this);
                break;
            case R.id.user_select_from_lib:
                //相册
                phoneType = 2;
                MyAccountActivityPermissionsDispatcher.needPermissionWithCheck(this);
                break;
        }
    }

    private void editPhoto() {
        // 选择相册或是拍照
        showPhotoDialog();
    }

    private BaseBottomDialog myDialog = null;

    //拍照相册选择dialog
    private void showPhotoDialog() {
        myDialog = BottomDialog.create(getSupportFragmentManager())
                .setLayoutRes(R.layout.activity_my_photo_edit)
                .setDimAmount(0.5f)            // Dialog window 背景色深度 范围：0 到 1，默认是0.2f
                .setCancelOutside(false)     // 点击外部区域是否关闭，默认true
                .setTag("BottomDialog")     // 设置DialogFragment的tag
                .setViewListener(new BottomDialog.ViewListener() {      // 可以进行一些必要对View的操作
                    @Override
                    public void bindView(View v) {
                        dialogClick(v);
                    }
                })
                .show();

    }

    private void dialogClick(View v) {
        View user_take_photo = v.findViewById(R.id.user_take_photo);
        View user_select_from_lib = v.findViewById(R.id.user_select_from_lib);
        View user_photo_cancel = v.findViewById(R.id.user_photo_cancel);

        user_take_photo.setOnClickListener(this);
        user_select_from_lib.setOnClickListener(this);

        user_photo_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myDialog.dismiss();
            }
        });
    }

    private void editPhone() {
        UserInfoUtils utils = UserInfoUtils.getUserInfoUtilsInstance();
        String phoneNum = utils.getMobile();
        Log.i(TAG, "phoneNum: " + phoneNum);

        // 账户绑定
        if (phoneNum != null && !phoneNum.isEmpty()) {
            // 旧手机
            Intent intent = new Intent(mContext,
                    YzCodeActivity.class);
            intent.putExtra("pNum", phoneNum);
            startActivity(intent);
        }
    }


    @NeedsPermission({Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
    void needPermission() {
        if (myDialog != null) {
            myDialog.dismiss();
        }

        TakePhoto takePhoto = getTakePhoto();
        switch (phoneType) {
            case 1:
                takePhoto();
                break;
            case 2:
                getTakePhoto();
                choosePhoto();
                break;
        }
    }

    //拍照成功
    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        ArrayList<TImage> images = result.getImages();

        showImg(images);
    }

    /**
     * 上传照片
     *
     * @param images
     */
    private void showImg(ArrayList<TImage> images) {
        String compressPath = images.get(0).getCompressPath();
        if (compressPath != null && !TextUtils.isEmpty(compressPath)) {

            MyApplication.getInstance().getHttpTools().uploadHeadImg(new File(compressPath), new StringCallback() {

                @Override
                public void onSuccess(Response<String> response) {
                    Log.i(TAG, "上传照片: " +response.body());
                    try {
                        JSONObject json = new JSONObject(response.body());

                        if ("0".equals(json.optString("error"))) {
                            changePhoto(json.getString("url"));
                        }else{
                            myDialog.dismiss();
                            ToastUtils.showShortToast(mContext, ""+json.optString("info"));
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                        ToastUtils.showShortToast(mContext, "数据错误请重试");
                    }

                }

                @Override
                public void onError(Response<String> response) {
                    super.onError(response);
                    Log.i(TAG, response.body());
                    ToastUtils.showShortToast(mContext, "请求失败,请重试!");

                }

                @Override
                public void onFinish() {
                    super.onFinish();
                }
            });
        } else {
            ToastUtils.showShortToast(mContext, "获取路径失败,请重新拍照");
        }
    }

    /**
     * 上传修改图片地址
     * @param url
     */
    private void changePhoto(String url){
        try {
            MyApplication.getInstance().getHttpTools().uploadHeadUrl(url, new StringCallback() {
                @Override
                public void onSuccess(Response<String> response) {
                    Log.i(TAG, "上传头像地址: " + response.body());

                    try {
                        JSONObject gson = new JSONObject(response.body());

                        if (gson != null) {
                            if (gson.optInt("code") < 1000) {

                                // 修改头像
                                Event event = new Event(EventCodes.EventMyCode.A, url);
                                EventBusUtil.sendEvent(event);

                                utils.setHeadImg("" + url);

                                ToastUtils.showShortToast(mContext, gson.optString("msg"));

                                // 加载圆形头像
                                RequestOptions options = new RequestOptions().bitmapTransform(new CircleCrop())
                                        .placeholder(R.mipmap.home_nomphoto) //图片加载出来前，显示的图片
                                        .fallback(R.mipmap.home_nomphoto)  //url为空的时候,显示的图片
                                        .error(R.mipmap.home_nomphoto); //图片加载失败后，显示的图片

                                Glide.with(mContext)
                                        .load(utils.getHeadImg())
                                        .apply(options)
                                        .into(myInfoPic);

                            } else {
                                ToastUtils.showShortToast(mContext, gson.optString("msg"));
                            }
                        }
                    } catch (Exception e) {
                        ToastUtils.showShortToast(mContext, "数据解析异常");
                    }
                    myDialog.dismiss();
                }

                @Override
                public void onError(Response<String> response) {
                    super.onError(response);
                    ToastUtils.showShortToast(mContext, "网络或服务器错误");
                    myDialog.dismiss();
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void takeFail(TResult result, final String msg) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.e(TAG, "------takeFail------" + msg);
                ToastUtils.showShortToast(mContext, "拍照失败" + msg);
            }
        });
    }

    @Override
    public void takeCancel() {
        Log.e(TAG, "------takeCancel------");
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        MyAccountActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
    }

    @OnShowRationale({Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
    void onShow(final PermissionRequest request) {
        new AlertDialog.Builder(mContext)
                .setMessage("此功能需要<相机,相册>权限,请允许")
                .setPositiveButton("允许", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        request.proceed();//继续执行请求
                    }
                }).setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                request.cancel();//取消执行请求
            }
        }).show();
    }

    @OnPermissionDenied({Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
    void onDenied() {
        ToastUtils.showShortToast(mContext, "权限不足,您没有开启此应用的相机权限。请到系统设置-->权限管理 开启相机权限。如果您的手机上安装了第三方应用管家（360管家，腾讯管家等），请开启一下权限！");

    }

    @OnNeverAskAgain({Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
    void askAgain() {
        ToastUtils.showShortToast(mContext, "权限不足,您没有开启此应用的相机权限。请到系统设置-->权限管理 开启相机权限。如果您的手机上安装了第三方应用管家（360管家，腾讯管家等），请开启一下权限！");

    }

    @Override
    protected void receiveEvent(Event event) {
        if (event.getCode() == EventCodes.EventMyCode.B) {
            String mobile = event.getData().toString();
            if (!TextUtils.isEmpty(mobile)) {
                mobile = mobile.replace(mobile.substring(3, 7), "****");
            }
            myInfoPhone.setText(mobile);

        }
    }

    ZhiWenDialog zhiWenDialog;//验证指纹
    DJLM_PasswordDialog mimaDialog;//输入密码
    MyUsualyDialog progressDialog;//等待对话框

    private void guanbizhiwen() {
        //先弹出指纹验证对话框，成功了，请求服务端关闭
        zhiWenDialog.setZhiWenCallBack(new ZhiWenCallBack() {
            @Override
            public void onSuccess() {
                ToastUtils.showShortToast(mContext, "指纹验证成功!");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        guanbiZhiWenSubmitServer();//指纹验证成功后，输入支付密码
                    }
                }, 500);
            }

            @Override
            public void onError(String msg) {
                ToastUtils.showShortToast(mContext, "指纹验证失败:" + msg);
            }

            @Override
            public void onShowPwdDialog() {
                ToastUtils.showShortToast(mContext, "选择密码支付");
            }
        });
        zhiWenDialog.show(getSupportFragmentManager(), "关闭指纹支付");

    }

    private void guanbiZhiWenSubmitServer() {
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        progressDialog = new MyUsualyDialog(mContext, R.layout.wait_item);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();


        UserInfoUtils userInfoUtils = UserInfoUtils.getUserInfoUtilsInstance();
        String phone_os = userInfoUtils.getPhoneOs();
        String phone_type = userInfoUtils.getPhoneType();
        String phone_brand = userInfoUtils.getPhoneBrand();
        String phone_imei = userInfoUtils.getPhoneImei();
        String touch_pwd = PrefUtils.getString(ConstantsValue.ZHIWEN_KEY, "");

        MyApplication.getInstance().getHttpTools().zwClose(
                phone_brand, phone_imei, phone_os, phone_type, touch_pwd, "1", "",
                new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                Log.i(TAG, "response: " + response.body());
                progressDialog.dismiss();
                try {
                    JSONObject json = new JSONObject(response.body());
                    if (json.getInt("code") == 200) {
                        PrefUtils.putString(ConstantsValue.ZHIWEN_KEY, "");
                        PrefUtils.putBoolean(ConstantsValue.ZHIWEN_STATE, false);
                        myFingerSwitch.setChecked(false);
                        ToastUtils.showShortToast(mContext, "关闭成功！");
                    } else {
                        ToastUtils.showShortToast(mContext, json.getString("msg"));
                    }
                } catch (Exception e) {
                    ToastUtils.showShortToast(mContext, "数据解析异常");
                }
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                progressDialog.dismiss();
                ToastUtils.showShortToast(mContext, "网络或服务器错误");
            }
        });

    }


    private void zhiwen(boolean isChecked) {
        myFingerSwitch.setChecked(!isChecked);//先设置原始状态
        if (isChecked) {
            zhiWenDialog.setZhiWenCallBack(new ZhiWenCallBack() {
                @Override
                public void onSuccess() {
                    ToastUtils.showShortToast(mContext, "指纹验证成功!");
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            yanzhengmima();//指纹验证成功后，输入支付密码
                        }
                    }, 500);
                }

                @Override
                public void onError(String msg) {
                    ToastUtils.showShortToast(mContext, "指纹验证失败:" + msg);
                }

                @Override
                public void onShowPwdDialog() {
                    ToastUtils.showShortToast(mContext, "选择密码支付");
                }
            });
            zhiWenDialog.show(getSupportFragmentManager(), "开启指纹支付");
        } else {
            //关闭
            //ToastUtils.showShortToast(SetActivity.this, "关闭指纹支付功能！");
            guanbizhiwen();

        }

    }

    /**
     * 输入完支付密码后，验证支付密码获取密钥
     */
    private void yanzhengmima() {
        mimaDialog = new DJLM_PasswordDialog(mContext);
        mimaDialog.setCallBack(new PasswordDialogListener() {
            @Override
            public void onDoneInput(DJLM_PasswordDialog dialog, String pwd) {
                //密码输入完成
                dialog.dismiss();
                getZhiWenKey(pwd);
            }

            @Override
            public void successFinger(DJLM_PasswordDialog dialog) {

            }

            @Override
            public void onBtnClick(int type) {
                if (type == 1) {
                    //加宽按钮点击
                    startActivity(new Intent(mContext, AddMoneyActivity.class));
                } else if (type == 2) {
                    //忘记密码按钮点击
                    startActivity(new Intent(mContext, ForgetPwdActivity.class));
                }
            }
        });
        mimaDialog.show(getSupportFragmentManager(), "密码");
        mimaDialog.setEnableFinger(false);
        //隐藏余额
        mimaDialog.setGone(true);
    }

    private void getZhiWenKey(String pwd) {

        Log.i(TAG, "getZhiWenKey: 支付密码：" + pwd);
        progressDialog = new MyUsualyDialog(mContext, R.layout.wait_item);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();

        UserInfoUtils userInfoUtils = UserInfoUtils.getUserInfoUtilsInstance();
        String phone_os = userInfoUtils.getPhoneOs();
        String phone_type = userInfoUtils.getPhoneType();
        String phone_brand = userInfoUtils.getPhoneBrand();
        String phone_imei = userInfoUtils.getPhoneImei();


        MyApplication.getInstance().getHttpTools().zwClose(
                phone_brand, phone_imei, phone_os, phone_type, "", "",pwd, new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Log.i(TAG, "onSuccess: " + response.body());

                        progressDialog.dismiss();
                        try {
                            JSONObject json = new JSONObject(response.body());
                            if (json.getInt("code") == 200) {
                                String touch_pwd = json.getString("touch_pwd");
                                if (!TextUtils.isEmpty(touch_pwd)) {
                                    PrefUtils.putString(ConstantsValue.ZHIWEN_KEY, touch_pwd);
                                    PrefUtils.putBoolean(ConstantsValue.ZHIWEN_STATE, true);
                                    myFingerSwitch.setChecked(true);
                                    ToastUtils.showShortToast(mContext, "开启成功！");
                                } else {
                                    ToastUtils.showShortToast(mContext, "开启失败，服务端返回的数据不正确！");
                                }
                            } else {
                                ToastUtils.showShortToast(mContext, json.getString("msg"));
                            }
                        } catch (Exception e) {
                            ToastUtils.showShortToast(mContext, "数据解析异常");
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        progressDialog.dismiss();
                        ToastUtils.showShortToast(mContext, "网络或服务器错误");
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBusUtil.unregister(mContext);
        mUnbinder.unbind();
    }

}
